package gui.NetworkManager;

import gui.Login.MessageCenter;
import gui.ParkingLotManager.ParkingLotManagerGUI;
import gui.ParkingLotManager.QuarterReportScreen;
import gui.ParkingLotManager.SetRatesScreen;
import gui.client.ClientGUI;

import java.awt.Color;
import java.awt.SystemColor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.border.TitledBorder;

import control.LoginController;
import control.MessageController;

import system.SystemTypes;
import system.VCP;
import vcpClasses.Notification;
import vcpClasses.ParkingLot;
import vcpClasses.Worker;
/**
 * this class use as the main menu for the Network Manager 
 * @author G8
 *
 */
public class NetworkManagerGUI extends ParkingLotManagerGUI implements ActionListener{
	private JButton btnReports;
	private JButton btnROData;
	private JButton btnSituation;
	private JComboBox comboBoxConLot;
	private ReportMenuScreen reportMenuScreen;
	private ReadOnlyDataScreen readOnlyDataScreen;
	private SituationScreen situationScreen;
	private MessageCenter messageCenter;
	/**
	 * Network Manager GUI Screen Constructor 
	 */
	public NetworkManagerGUI() {
		super();
		Initialize();
	}
	/**
	 * This method contains the view of the Panel
	 */
public	void Initialize(){
		setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Network Manager Menu", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0)));
		setBackground(SystemColor.menu);
		setBounds(VCP.guiX,VCP.guiY,500,400);
		setLayout(null);
		VCP.frame.setBounds(this.getBounds());
		
		btnReports = new JButton("Reports Menu");
		btnReports.setBounds(20, 167, 207, 46);
		btnReports.addActionListener(this);
		add(btnReports);
		
		btnROData = new JButton("View Read-only Data");
		btnROData.setBounds(20, 224, 207, 46);
		btnROData.addActionListener(this);
		add(btnROData);
		
		btnSituation = new JButton("View Situation");
		btnSituation.setBounds(20, 281, 207, 46);
		btnSituation.addActionListener(this);
		add(btnSituation);
		
		JLabel lblConLot = new JLabel("Control Lot:");
		lblConLot.setBounds(300, 68, 121, 14);
		add(lblConLot);
		
		comboBoxConLot = new JComboBox();
		comboBoxConLot.setBounds(393, 65, 78, 20);
		comboBoxConLot.addActionListener(this);
		for (int i=1;i<7;i++)
			comboBoxConLot.addItem(i);
		add(comboBoxConLot);
		
		VCP.currentLot = new ParkingLot(1); // Set default lot to control as lot no.1
}
/**
 * This method listens to the buttons on the panel
 * @param e is the buttons the user Click
 */
	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == comboBoxConLot){ // Set Network Manager Association for specific Lot Control
			VCP.currentLot = new ParkingLot((int) comboBoxConLot.getSelectedItem());
		}
		if (e.getSource() == btnClientMenu){
			clientGUI = new ClientGUI();
			VCP.setScreen(this, clientGUI);
		}
		if (e.getSource() == btnMessage){
			try{
			messageCenter = new MessageCenter();
			VCP.setScreen(this, messageCenter);
			}
			catch(Exception ae){
				JOptionPane.showMessageDialog(null, "No new messages !", "Attention",
	                    JOptionPane.INFORMATION_MESSAGE);
			}
		}
		if (e.getSource() == btnReports){
			reportMenuScreen = new ReportMenuScreen();
			VCP.setScreen(this, reportMenuScreen);
		}
		if (e.getSource() == btnROData){
			readOnlyDataScreen = new ReadOnlyDataScreen();
			VCP.setScreen(this, readOnlyDataScreen);
		}
		if (e.getSource() == btnSituation){
			situationScreen = new SituationScreen();
			VCP.setScreen(this, situationScreen);
		}
		if (e.getSource() == btnQuarterReport){
			quarterReportScreen = new QuarterReportScreen();
			VCP.setScreen(this, quarterReportScreen);
		}
		if (e.getSource() == btnSetRates){
			setRatesScreen = new SetRatesScreen();
			VCP.setScreen(this, setRatesScreen);
		}
		if (e.getSource() == btnLogout){
			SystemTypes userToLogout = new SystemTypes(VCP.currentUser,null);
			boolean logoutRes = LoginController.LogOut(userToLogout);
			if (logoutRes)
				VCP.setGUI(0, this);
			else{
				JOptionPane.showMessageDialog(null, "Failed to logout!", "Error",
	                    JOptionPane.ERROR_MESSAGE);
			}
		}	
	}
}
